import unittest
import math
import os
import difflib
import sys
from fractions import Fraction as F

from abcesac import abc_to_esac
from abcesac.parser import ABCParser
from abcesac.music import Song
from abcesac.grouper import TemperleyGrouper

class TemperleyGrouperTestCase(unittest.TestCase):

    def test_grouper(self):
        abc = open('data/czech01.abc').read()
        esac = open('data/czech01.esac').read().strip()
        grouper = TemperleyGrouper()
        result = abc_to_esac(abc, group=True)
        if result != esac:
            diff = list(difflib.Differ().compare(result.splitlines(1), esac.splitlines(1)))
            for l in diff:
                print l.strip()
            self.fail('test failed!')

    def test_tuples_grouper(self):
        abc = open('data/fling.abc').read()
        esac = open('data/fling.esac').read().strip()
        grouper = TemperleyGrouper()
        result = abc_to_esac(abc, group=True)
        if result != esac:
            diff = list(difflib.Differ().compare(result.splitlines(1), esac.splitlines(1)))
            for l in diff:
                print l.strip()
            self.fail('test failed!')

if __name__ == '__main__':
    unittest.main()
